
package model.test;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author FELIPE & NICOLAS
 */
public class MCQ extends Question{
    
    
    private ArrayList<String> possAns;      //ArrayList of possible Answers
    private int corrAns;                    //int containing the position of the correct answer in the ArrayList of option
    
    //class consructor1
    public MCQ(String questionTxt,int marks,float penalty,ArrayList<String> possAns,int corrAns,String imageFile){
        
        super(questionTxt,marks,penalty,imageFile);//superclass constructor
        this.type="MCQ";         //variable from superclass
        this.possAns= possAns;   //ArrayList containing possible answers
        this.corrAns=corrAns;    //corrAnswer (index position in arraylist of options)
        
    }
    
    ////constructor 2 (from a string readed from a txt file, which has been pased by the SUBSECTION constructor)
    public MCQ(String inputString){
        
        super("empty",0,0,""); //trick, then modify it
        
        possAns = new ArrayList<String>();
        
        String[] readResultQuestion = inputString.split("~"); //readResultQuestion is an array that represents each question, which contain the info about the question
        
        //data about the question
        this.type = readResultQuestion[0];              //it has to be MCQ
        this.questionTxt = readResultQuestion[1];
        this.marks =Integer.parseInt(readResultQuestion[2]);
        this.penalty =Float.parseFloat(readResultQuestion[3]);
        this.corrAns =Integer.parseInt(readResultQuestion[4]);
        this.imageFile = readResultQuestion[5];
        
        //get the possible answers
        String[] readResultPossAns = readResultQuestion[6].split("&");
        
        for (int l=0;l<readResultPossAns.length;l++){
           possAns.add(readResultPossAns[l]);
        }
        
    }
    
       
    //toString method
    public String toString(){
        return this.type + "~" +this.questionTxt+ "~" + this.marks+ "~" + this.penalty+"~"+this.corrAns+ "~"+this.imageFile+"~"+this.toStringPossAns();
    }
    
    
    //toString method for possibleAnswers to insert in the normal toString method
    public String toStringPossAns(){
        
        Iterator<String> iter =possAns.iterator();
        String result=iter.next();
        
        while ( iter.hasNext() ){
            result=result+"&"+iter.next();
        }
        
        return result;
    }
    
    
    //GETTERS AND SETTERS

    public int getCorrAns() {
        return corrAns;
    }

    public void setCorrAns(int corrAns) {
        this.corrAns = corrAns;
    }

    public ArrayList<String> getPossAns() {
        return possAns;
    }

    public void setPossAns(ArrayList<String> possAns) {
        this.possAns = possAns;
    }

    public int getMarks() {
        return marks;
    }

    public void setMarks(int marks) {
        this.marks = marks;
    }
    
    public float getPenalty() {
        return penalty;
    }

    public void setPenalty(int penalty) {
        this.penalty = penalty;
    }

    public String getQuestionTxt() {
        return questionTxt;
    }

    public void setQuestionTxt(String questionTxt) {
        this.questionTxt = questionTxt;
    }

    public String getType() {
        return type;
    }
    
    public void setImageFile(String imageFile) {
        this.imageFile = imageFile;
    }

    public String getImageFile() {
        return imageFile;
    }

    //u cannot change the type of question
    //public void setType(String type) {
      //  this.type = type;
    //}

    
    
    
    
    //FOR TESTING PURPOSE
    public static void main(String[] args) {
	
         //create a MCQ and show it
         ArrayList<String> possAnswers = new ArrayList<String>();
         possAnswers.add("optionA");
         possAnswers.add("optionB");
         possAnswers.add("optionC");
	 MCQ temp = new MCQ("What is?",10,15,possAnswers,2,"carrot.jgp");
         System.out.println(temp);
         MCQ temp2 = new MCQ("MCQ~What is?~10~15.0~2~carrot.jgp~optionA&optionB&optionC");
         System.out.println(temp2.imageFile);

    }
    
    
}
